package com.teamwork.ZuccEcho.Repository;

import com.teamwork.ZuccEcho.Entity.Qnquestion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface QuestionApiRepository extends JpaRepository<Qnquestion, Long> {
    Qnquestion findById(long id);

    @Query(value="select count(*) from question", nativeQuery = true)
    Long countAll();

    @Query(value="select * from question where question.q_name = ?1", nativeQuery = true)
    Qnquestion searchModelByName(String mname);

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO question(q_name) VALUES (?1)",nativeQuery = true)
    boolean insertModel(String question_qName);

    @Transactional
    @Modifying
    @Query(value="DELETE from question where question.q_id= ?1", nativeQuery = true)
    void deleteQuestionByQId(long question_Id);

    @Query(value="UPDATE question SET q_name = ?1 WHERE q_id = ?2", nativeQuery = true)
    boolean modifyQuestionByMId(String name,long question_Id);
}
